package com.example.esc_im_client.db;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import android.content.Context;

import com.example.esc_im_client.common.base.BaseResponseDTO;
import com.example.esc_im_client.utils.HttpUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
//import org.json.JSONObject;

/**
 * @ClassName: WelcomeMapper
 * @Description:
 * @Author: 墨渍
 * @Date: 2023/9/25 23:17
 **/
public class WelcomeMapper {

    private Context context;

    public WelcomeMapper(Context context) {
        this.context = context;
    }


    public String upInWelcome(String url, Context context){
        String photo = "";
        DatabaseHelper dbHelper = new DatabaseHelper(context); // 传入上下文

        HttpUtils.doGet("http://192.168.3.4:8081/robot/welcome", new HttpUtils.HttpCallback() {
//        HttpUtils.doGet("http://www.baidu.com", new HttpUtils.HttpCallback() {
            @Override
            public void onSuccess(String response) {
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        BaseResponseDTO baseResponseDTO = JSONObject.parseObject(response, BaseResponseDTO.class);
                        Integer code = baseResponseDTO.getCode();
                        if (200 != code){
                            Log.d("欢迎页请求失败", response);
                        }else {
                            Log.d("欢迎页请求成功", response);
                            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(baseResponseDTO.getData()));
                            String url1 = jsonObject.getString("url");
                            String customSQL = "select * from t_welcome";
//                            dbHelper.getWritableDatabase().execSQL(customSQL);
                            Cursor cursor = dbHelper.getReadableDatabase().rawQuery(customSQL, null);
                        }

                    }
                });
            }

            @Override
            public void onError(String errorMessage) {
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Log.d("请求失败", errorMessage);
                    }
                });
            }
        });

//        String customSQL = "INSERT INTO t_welcome (url, file) VALUES ('www.baidu.com', 'UklGRqQRAABXRUJQVlA4IJgRAADwRACdASqWAJYAPqFCm0kmI6IhLHb82MAUCWYS4BiAZhIcx/ZWdyf0v9l5FpF1tD0p/2z0guipznXpw3nL+u+pLOzev/zd/Ntsq+fap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9b+dHvAygUfpO4YZnnw2xbDhxtz7ZILWAKfSk2gNrgk/Mp1EplLixfw7p4L1GDTukEaCxqZkJfAqi2F37JxdufNFiCBZ1VJVebHPmt5vVRM6EVxz/VVzjM9ONrfLxfMUNZvT/uJUxZNS2mzrNhRhS2C77W8PIZEgiERZ+iVfapZcuQerVm77ujfP/KFYUtqxJCJrrh9J+QhwtuslxkUeQ0ECp3OmnjNIZbSdzuZxh9F2Ey/VyrbtqqM50+MySLuJWIJ6f96UOO6ia1wvNyBPiUBl65MYsk+QlHzApPX+0UWTeieX1JNFVwk0gF46lFwnLUXYEuiGmMCoVVPv2WvZp/fKUGRvh8vjJ33F8r5BNbKQZrkjYnRT+lSvksDJurxk9+eg/iVkOSuFALO4tLfMB4N1SmqHqeD34ensmTvVlmUXIWgLbp+rNjSuJMjL9Tv5l6xpiTCMoOVj/TYZWCNhLGHQr02lxXyN1sMaHw9TdKAA')";
        String customSQL = "INSERT OR REPLACE INTO t_welcome (url, file) VALUES ('your_url_value', 'your_file_value');\n";
        dbHelper.executeSQL(customSQL); // 执行自定义的 SQL 语句
        dbHelper.close();
        Log.d("sql链接关闭","已关闭");
        return photo;
    }
}
